package gui.treenodes;

import java.util.ArrayList;
import java.util.List;

public class RootTransactionTreeNode implements ParentTransactionTreeNode
{
	private String name;
	private List<TransactionTypeNode> typeNodes;
	
	public RootTransactionTreeNode(String name){
		this.name = name;
		typeNodes = new ArrayList<TransactionTypeNode>();
	}

	public int add(TransactionTypeNode e){
		typeNodes.add(e);
		return typeNodes.indexOf(e);
	}
	
	public TransactionTypeNode getNode(String type){
		for(TransactionTypeNode node : typeNodes){
			if(node.getType().equals(type)){
				return node;
			}
		}
		return null;
	}

	@Override public TransactionTreeNode getNodeAt(int index){
		return typeNodes.get(index);
	}

	@Override public int getIndex(Object o){
		return typeNodes.indexOf(o);
	}

	public void remove(TransactionTypeNode e){
		typeNodes.remove(e);
	}
	
	@Override public double getAmmount(){
		double result = 0;
		for(TransactionTypeNode node : typeNodes){
			result += node.getAmmount();
		}
		return result;
	}

	@Override public int getChildCount(){
		return typeNodes.size();
	}
	
	@Override public String toString(){
		return name;
	}
}
